package com.annotation.filter;

import org.springframework.core.io.Resource;
import org.springframework.core.type.AnnotationMetadata;
import org.springframework.core.type.ClassMetadata;
import org.springframework.core.type.classreading.MetadataReader;
import org.springframework.core.type.classreading.MetadataReaderFactory;
import org.springframework.core.type.filter.TypeFilter;

import java.io.IOException;

public class CustomerTypeFilter implements TypeFilter {
    /**
     * @param metadataReader        当前类的信息，正在扫描的类的信息,里面主要有三个对象：Resource ：类的资源信息，ClassMetadata  类的原信息  ，AnnotationMetadata 该类的元注解信息
     * @param metadataReaderFactory 工厂类，不仅是当前类，也可以获取其他信息类
     * @return
     * @throws IOException
     */
    public boolean match(MetadataReader metadataReader, MetadataReaderFactory metadataReaderFactory) throws IOException {
        //TODO Auto-generated method stub
        // 获取当前正在扫描的类的注解信息
        AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();


        // 获取当前正在扫描的类的类型信息
        ClassMetadata classMetadata = metadataReader.getClassMetadata();


        String className = classMetadata.getClassName();
        if (className.equals("com.annotation.filter.CustomerTypeFilter")) {
            return true;
        }
        String[] interfaceNames = classMetadata.getInterfaceNames();

        // 获取当前类的路径信息
        Resource resource = metadataReader.getResource();

        String filename = resource.getFilename();
        return false;
    }
}
